﻿using System;
using System.Windows.Forms;
using System.Drawing;

namespace EffortsTracker
{
    public partial class TrackerView : Form
    {
        private NotifyIcon trayIcon;
        private ContextMenu trayMenu;

        public TrackerView()
        {
            InitializeComponent();
            // Create a simple tray menu with only one item.
            trayMenu = new ContextMenu();

            trayMenu.MenuItems.Add("Show", OnShowTray);
            trayMenu.MenuItems.Add("Close", OnCloseTray);


            // Create a tray icon. In this example we use a
            // standard system icon for simplicity, but you
            // can of course use your own custom icon too.
            trayIcon = new NotifyIcon();
            trayIcon.Text = "MyTrayApp";
            trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
            //trayIcon.Icon = new Icon(@"D:\GLGL\Icons\Adobe-PDF-Document.ico");

            // Add menu to tray icon and show it.
            trayIcon.ContextMenu = trayMenu;
            trayIcon.Visible = true;
            trayIcon.MouseDoubleClick += new MouseEventHandler(trayIcon_MouseDoubleClick);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //panel1.Controls.Add(new TrackerUserControl());
            panel1.Controls.Add(new ProjectsView(this));
        }
        void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
        }

        private void OnCloseTray(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void OnShowTray(object sender, EventArgs e)
        {
            this.Show();
        }

        private void TrackerView_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }
    }
}